from manim import *



class math2(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])


          #镜头跟进效果
        self.camera.frame.save_state()
        text0=Text("变形构造",color=PINK).scale(5.0).move_to([0,0,0])
        self.play(Create(text0),FadeIn(dot1),FadeIn(dot2),FadeIn(dot3),self.camera.frame.animate.scale(0.6).move_to([0,0,0])) 
        self.wait()
        #镜头拉回
        self.play(Restore(self.camera.frame))
         #中心主题+框框标记
        text1 = Tex(r"\text{变形构造}",color=PINK
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,5,0])
        self.play(
            ReplacementTransform(text0,text1)
        )
        self.wait(0.5)
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-30, 5, 0])
        self.play(Create(rectangle))
        #箭头引出
        arrow = Arrow(start=[-22,7.5,0],end=[-15,15,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text2 = Tex(r"\text{取对数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,15,0])
        #箭头1引出
        arrow1 = Arrow(start=[-22,5,0],end=[-15,5,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本3
        text3 = Tex(r"\text{ 去分母 }"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,5,0])
  
        #箭头2引出
        arrow2 = Arrow(start=[-22,2.5,0],end=[-15,-5,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本4
        text4 = Tex(r"\text{ 去平方,倒代换 }"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-5,0])
        #箭头
        arrow3 = Arrow(start=[-22,0,0],end=[-15,-15,0], color=RED
                       , stroke_width=20, tip_length=1)
        text8 = Tex(r"\text{去根号(配合ln)}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-4,-15,0])
        self.play(Create(text8),Create(text4),Create(text3),Create(text2),Create(arrow),Create(arrow1)
                  ,Create(arrow2),Create(arrow3))
        
    

        #清空
        self.play(FadeOut(text8),FadeOut(text4),FadeOut(text3),FadeOut(text2),FadeOut(arrow),FadeOut(arrow1)
                  ,FadeOut(arrow2),FadeOut(arrow3)
                  ,FadeOut(rectangle),FadeOut(text1))
        #题目
        text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-35,7.5,0])
        #题目出现
        text = Tex(r"\text{证明：}$\sqrt{\dfrac{1-x}{1+x}} <\dfrac{\ln \left( 1+x\right) }{\arcsin x}$\text{,其中}$0 <x <1$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0)
        

        self.play(Write(text),self.camera.frame.animate.scale(0.8))
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        Create(text100)
        #题目向上移动
        self.play(text.animate().scale(0.8).move_to(UP*20)) 

        #镜头拉近
        self.play(self.camera.frame.animate.scale(0.8).move_to([0,20,0]))


        #箭头引出
        arrow = Arrow(start=[10,25,0],end=[6,23,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        #文本
        long_text=("特征识别:\n"
                     "去分母")
        text1 = Text(long_text,color=YELLOW,
                   font_size=200).move_to([17,25,0])
        #框框标
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=6
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-4, 20, 0])
        self.play(Create(rectangle),Create(text1))

        #成长箭头####
        arrow1 = Arrow(start=[0,15,0],end=[0,8,0] ,color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow1))

        text2 = Tex(r"$\sqrt{1-x}\arcsin x <\sqrt{1+x}\ln \left( 1+x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,5,0])
        self.play(Write(text2))
        #框框标记

        #文本
        long_text1=("特征识别:\n"
                     "去根号")
        text1 = Text(long_text1,color=YELLOW,
                   font_size=200).move_to([30,5,0])
        #框框标
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=9,height=6
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([5, 5, 0])
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=8,height=6
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([-16, 5, 0])


        self.play(Create(rectangle1),Create(rectangle2),Create(text1))
        #文本
        self.play(Restore(self.camera.frame))
        text2 = Tex(r"$?$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).move_to([-5,0,0])
        self.play(Create(text2))




        self.play(FadeOut(text2))

        #文本
        text3 = Tex(r"$\left( \arcsin x\right) ^{'}=\dfrac{1}{\sqrt{1-x^{2}}}$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-5,0])
        text4 = Tex(r"$\left( \ln \left( 1+x\right) \right) ^{'}=\dfrac{1}{1+x}$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-15,0])
        self.play(Create(text4),Create(text3))
        #框框标记
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=9,height=6
                            ,stroke_color=PURE_RED,stroke_width=20)
        rectangle3.move_to([5, 5, 0])
        self.play(Create(rectangle3))
        self.play(FadeOut(text4),FadeOut(text3))

        #箭头

        arrow2 = Arrow(start=[0,0,0],end=[0,-5,0] ,color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow2))

        text5 = Tex(r"$\sqrt{1-x^{2}}\arcsin x <\left( x+1\right) \ln \left( 1+x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-8,0])
        self.play(Write(text5))
        #丝滑变化
        text6 = Tex(r"$\sqrt{1-x^{2}}\arcsin x-\left( x+1\right) \ln \left( 1+x\right) <0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-8,0])

        self.play(
            ReplacementTransform(text5,text6)
        )
        #半透明矩阵扩展
        rectangle4=Rectangle(color=GREEN,fill_opacity=0.3,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-2,-8,0])
        self.play(
            rectangle4.animate.stretch(40.0,dim=0)
        )
        #文本

        text7 = Tex(r"\text{即证：}$F\left( x\right)  <0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,-12,0])
        
        self.play(Create(text7))
        arrow3 = Arrow(start=[-4,-12,0],end=[0,-12,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow3))

        #文本
        text8 = Tex(r"$F\left( 0\right) =0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([7,-12,0])
        
        self.play(Create(text8))

        arrow4 = Arrow(start=[13,-12,0],end=[17,-12,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow4))

        #文本
        text9 = Tex(r"$F\left( x\right) \downarrow $",color=YELLOW_C
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([23,-12,0])
        
        self.play(Create(text9))

        #文本

        text10 = Tex(r"$F^{'}\left( x\right) =\dfrac{-x}{\sqrt{1-x^{2}}}\arcsin x-\ln \left( 1+x\right)  $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-17,0])
        
        self.play(Create(text10))

        #框框标记
        rectangle5=Rectangle(color=BLUE,fill_opacity=0.0,width=9,height=6
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle5.move_to([-11, -17, 0])
        self.play(Create(rectangle5))
        text11 = Tex(r"$ <0 $",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle5,DOWN,buff=1)
        self.play(Create(text11))

        #框框移动
        self.play(rectangle5.animate().shift(9.7*RIGHT))
        text12 = Tex(r"$ >0 $",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle5,DOWN,buff=1)
        self.play(Create(text12))
        self.play(rectangle5.animate().shift(12.7*RIGHT).stretch(1.1,dim=0))
        text13 = Tex(r"$ >0 $",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle5,DOWN,buff=1)
        self.play(Create(text13))

        self.play(FadeOut(rectangle5))

        #文本
        text14 = Tex(r"$ <0 $",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text10,RIGHT,buff=2)
        self.play(Create(text14))

        #框框

        rectangle6=Rectangle(color=BLUE,fill_opacity=0.0,width=7,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle6.move_to([21, -17, 0])
        self.play(Create(rectangle6))

        ##框框移动
        self.play(rectangle6.animate().move_to([23,-12,0]).stretch(1.2,dim=0))
        self.play(rectangle6.animate().move_to([-11,-12,0]).stretch(1.3,dim=0))
        


        #清空
        #清空屏幕
        self.clear()
        #文本

        text13 = Tex(r"\text{(1000题)设}$ 0 <x <1,$\text{证明：}$\left( 1+x\right) \ln ^{2}\left( 1+x\right)  <x^{2}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,0,0])
        self.play(Write(text13),self.camera.frame.animate.scale(0.7).move_to([0,0,0]))









        self.play(Restore(self.camera.frame))
        self.wait(1)










        
















        
        self.wait()